#include <isa.h>
#include "local-include/reg.h"

const char *regs[] = {
    "$0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
    "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
    "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
    "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"};

void isa_reg_display()
{
  for (int i = 0; i < 32; i++)
    printf("%4s - 0x%08X\n", regs[i], cpu.gpr[i]._32);
  printf("  pc - 0x%08X\n", cpu.pc);
  return;
}

word_t isa_reg_str2val(const char *s, bool *success)
{
  for (int i = 0; i < 32; i++)
  {
    if (strcmp(regs[i], s) == 0)
    {
      *success = true;
      return cpu.gpr[i]._32;
    }
  }
  if (strcmp(s, "pc") == 0)
  {
    *success = true;
    return cpu.pc;
  }
  *success = false;
  return 0;
}
